#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-08-19 10:32 上午
# @Author  : yangdy
# @File    : 2020-08-19.647.回文子串
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def countSubstrings(self, s: str) -> int:
        ans = 0

        # def test(ss, ll, rr):
        #     if ll < 0 or rr >= len(ss):
        #         return False
        #     while ll < rr and ss[ll] == ss[rr]:
        #         ll, rr = ll+1, rr-1
        #     return ll >= rr
        ls = len(s)
        for i in range(ls):
            for u in [(i, i), (i, i+1)]:
                j, k = u[0], u[1]
                # while j >= 0 and k < ls and test(s, j, k):
                while j >= 0 and k < ls and s[j] == s[k]:
                    ans, j, k = ans+1, j-1, k+1
        return ans


questions = [
    ("abc",),
    ("aaa",),
]

work(questions, lambda q: Solution().countSubstrings(q[0]))
